package com.ruoyi.common.service.business.impl;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.SettingEnums;
import com.ruoyi.common.vo.business.setting.DeclarationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.mapper.business.SysSettingMapper;
import com.ruoyi.common.domain.business.SysSetting;
import com.ruoyi.common.service.business.SysSettingService;

/**
 * 设置Service业务层处理
 *
 * @author Song
 * @date 2024-10-29
 */
@Service
public class SysSettingServiceImpl extends ServiceImpl<SysSettingMapper, SysSetting> implements SysSettingService {

    @Autowired
    private SysSettingMapper sysSettingMapper;

    public JSONObject getSetting() {
        SysSetting one = getOne(new LambdaQueryWrapper<SysSetting>().eq(SysSetting::getSettingKey, SettingEnums.DECLARATION.getKey()));
        if (one!=null){
            return JSONUtil.parseObj(one.getDescription());
        }
        DeclarationVo vo = new DeclarationVo();
        return JSONUtil.parseObj(vo);
    }

    public void saveSetting(JSONObject jsonObject) {
        SysSetting setting = new SysSetting();
        setting.setSettingKey(SettingEnums.DECLARATION.getKey());
        setting.setDescription(JSONUtil.toJsonStr(jsonObject));
        saveOrUpdate(setting);
    }
}



